package com.itheima.service.impl;

import com.itheima.mapper.EmpMapper;
import com.itheima.mapper.StudentMapper;
import com.itheima.pojo.JobOption;
import com.itheima.pojo.StudentOption;
import com.itheima.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ReportServiceImpl implements ReportService {

    @Autowired
    private EmpMapper empMapper;

    @Autowired
    private StudentMapper studentMapper;
    @Override
    public JobOption getReport() {
        //调用mapper查询数据
        List<Map<String, Object>> jobData = empMapper.countEmpJobData();
        List<Object> jobList = jobData.stream().map(map -> map.get("pos")).toList();
        List<Object> dataList = jobData.stream().map(map -> map.get("sum")).toList();
        return new JobOption(jobList, dataList);
    }

    @Override
    public List<Map<String, Object>> GetGenderData() {
        //调用mapper查询数据
     List<Map<String, Object>>  list= empMapper.countEmpGenderData();
        return list;
    }

    @Override
    public List<Map<String, Object>> GetStudentDegreeData() {
       List<Map<String, Object>> list= studentMapper.countStudentDegreeData();
        return list;
    }

    @Override
    public StudentOption GetStudentCountData() {
        List<Map<String, Object>> list= studentMapper.countStudentData();
        List<Object> clazzList = list.stream().map(map -> map.get("name")).toList();
        List<Object> dataList = list.stream().map(map -> map.get("sum")).toList();
        return new StudentOption(clazzList, dataList);
    }
}

